package com.app.common;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

public class CycleChecker {

    public static boolean isCycleMet(LocalDate startDate, LocalDate endDate, String cycleUnit) {
        if (startDate == null || endDate == null || cycleUnit == null) {
            return true;
        }

        switch (cycleUnit) {
            case "YEARS":
                return startDate.plusYears(1).isAfter(endDate);
            case "QUARTERS":
                long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
                return daysBetween < 91.31;
            case "MONTHS":
                return startDate.plusMonths(1).isAfter(endDate);
            case "WEEKS":
                return startDate.plusWeeks(1).isAfter(endDate);
            default:
                throw new IllegalArgumentException("Unsupported cycle unit: " + cycleUnit);
        }
    }
}